home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Dialog / c / CreatDstry next >
Text File  |  1995-03-14  |  3KB  |  97 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Dialog.CreatDstry.c
  12.     Author:  Copyright © 1993 Tim Browse and Jason Williams
  13.     Version: 1.01 (02 Mar 1993)
  14.     Purpose: Very high level window (dialogue) handling -
  15.              Creating and destroying dialogues
  16. */
  17.  
  18. #include <stdlib.h>
  19.  
  20. #include "DeskLib:Wimp.h"
  21. #include "DeskLib:WimpSWIs.h"
  22.  
  23. #include "DeskLib:Dialog.h"
  24. #include "DeskLib:Event.h"
  25. #include "DeskLib:Window.h"
  26.  
  27.  
  28. static BOOL EventHandler(event_pollblock *event, void *reference)
  29. {
  30.   dialog_record *dbox = (dialog_record *) reference;
  31.  
  32.   switch (event->type)
  33.   {
  34.      case event_CLOSE:
  35.       /*  User has clicked on close icon - We just close the window, as
  36.        *  Dialog_WaitForClick will notice this and take appropriate action
  37.        */
  38.       Window_Hide(dbox->window);
  39.       return(TRUE);
  40.  
  41.     case event_CLICK:
  42.       /* Ignore work-area click events */
  43.       if (event->data.mouse.icon >= 0)
  44.       {
  45.           dbox->lastclicked   = event->data.mouse.icon;
  46.           dbox->button.value  = event->data.mouse.button.value;
  47.           dbox->state.persist = event->data.mouse.button.data.adjust;
  48.           return(TRUE);
  49.       }
  50.       break;
  51.   }
  52.  
  53.   return(FALSE);          /* Allow other event handlers to handle this event */
  54. }
  55.  
  56.  
  57. extern dialog Dialog_Create(char *template_name, int maxtitlesize)
  58. /*  Returns a pointer to a dialog record, or NULL if it fails */
  59. {
  60.   window_handle window;
  61.   dialog d;
  62.  
  63.   window = Window_Create(template_name, maxtitlesize);
  64.   if (window == NULL) return(NULL);
  65.  
  66.   d = (dialog) malloc(sizeof(dialog_record));
  67.   if (d == NULL) return(NULL);
  68.  
  69.   d->window         = window;
  70.   d->lastclicked    = dialog_NOCHOICE;
  71.   d->state.persist  = TRUE;
  72.   d->state.isstatic = d->state.stillopen = FALSE;
  73.  
  74.   /* Attach the event handler */
  75.   Event_Claim(event_NULL, event_ANY, event_ANY, EventHandler, d);
  76.   Event_Claim(event_ANY, window, event_ANY, EventHandler, d);
  77.  
  78.   return(d);
  79. }
  80.  
  81.  
  82. extern void Dialog_Destroy(dialog dbox)
  83. {
  84.   if (dbox != NULL)
  85.   {
  86.     Event_Poll();     /* for RO3 bug */
  87.  
  88.     /* Remove event handler */
  89.     Event_Release(event_NULL, event_ANY, event_ANY, EventHandler, dbox);
  90.     Event_Release(event_ANY, dbox->window, event_ANY, EventHandler, dbox);
  91.  
  92.     Dialog_Hide(dbox);
  93.     Window_Delete(dbox->window);
  94.     free(dbox);
  95.   }
  96. }
  97.